package com.itheima.controller;

import com.itheima.bean.Student;
import com.itheima.service.StudentServiceImpl;
import com.itheima.service.impl.StudentService;
import org.junit.Test;

import java.util.List;


public class StudentController {
    //创建业务层对象
    private StudentService service = new StudentServiceImpl();

    //查询全部功能测试
    @Test
    public void selectAll() {
        List<Student> list = service.selectAll();
        for (Student student : list) {
            System.out.println(student);
        }
    }

    //根据id查询功能测试
    @Test
    public void selectById() {
        Student student = service.selectStuById(3);
        System.out.println(student);
    }

    //新增功能测试
    @Test
    public void insert() {
        Student stu = new Student(4,"张三三",25);
        Integer insert = service.insert(stu);
        if(insert==1){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }

    //修改功能测试
    @Test
    public void update() {
        Student stu = new Student(2,"xiaohuang",25);
        Integer insert = service.update(stu);
        if(insert==1){
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }
    }

    //删除功能测试
    @Test
    public void delete() {

        Integer insert = service.delete(4);
        if(insert==1){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }


}
